/*
 * Line.cpp
 *
 *  Created on: 2011-02-23
 *      Author: kamil
 */

#include "mgr/util/Line.h"
#include <boost/assert.hpp>

Line::Line() {

}

Line::Line(double x1, double y1, double x2, double y2) : p1(x1,y1), p2(x2,y2)
{
	calcLineParams();
}

Line::Line(const Vector2d & _p1, const Vector2d & _p2) : p1(_p1), p2(_p2)
{
	calcLineParams();
}

Line::~Line() {

}


Vector2d Line::intersectionPoint(const Line & other){
	double W = (A * other.B) - (other.A * B);
	double Wx = (-C*other.B) + (other.C * B);
	double Wy = -(A * other.C) + (other.A * C);
	BOOST_ASSERT(W != 0);	// lines parallel!
	Vector2d result(Wx/W, Wy/W);
	return result;
}

void Line::calcLineParams(){
	Vector2d dirVec = p2 - p1;
	A = dirVec.y;
	B = -dirVec.x;
	C = - ( (p2.x * A) + (p2.y * B) );
}

//bool Line::intersectsWith(const Line & other){
//
//
//	if (x.intersectsWith(other.x) && y.intersectsWith(other.y)) return true;
//	return false;
//}

////////////////////////////////////////////
//bool Line::Interval::contains(double nr){
//	if (start <= nr && nr <= end) return true;
//	return false;
//}
//
//bool Line::Interval::intersectsWith(const Interval & other){
//	if (contains(other.start) || contains(other.end)) return true;
//	return false;
//}

